<!DOCTYPE html>
<!-- saved from url=(0049)https://www.cnblogs.com/magicalSam/p/7197533.html -->
<html lang="zh-cn"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Spring Boot 系列（七）Swagger2-生成RESTful接口文档 - 神奇Sam - 博客园</title>
<link type="text/css" rel="stylesheet" href="./Spring Boot 系列（七）Swagger2-生成RESTful接口文档 - 神奇Sam - 博客园_files/blog-common.css">
<link id="MainCss" type="text/css" rel="stylesheet" href="./Spring Boot 系列（七）Swagger2-生成RESTful接口文档 - 神奇Sam - 博客园_files/bundle-CodingLife.css">
<link id="mobile-style" media="only screen and (max-width: 767px)" type="text/css" rel="stylesheet" href="./Spring Boot 系列（七）Swagger2-生成RESTful接口文档 - 神奇Sam - 博客园_files/bundle-CodingLife-mobile.css">
<link title="RSS" type="application/rss+xml" rel="alternate" href="http://www.cnblogs.com/magicalSam/rss">
<link title="RSD" type="application/rsd+xml" rel="EditURI" href="http://www.cnblogs.com/magicalSam/rsd.xml">
<link type="application/wlwmanifest+xml" rel="wlwmanifest" href="http://www.cnblogs.com/magicalSam/wlwmanifest.xml">
<script async="" src="./Spring Boot 系列（七）Swagger2-生成RESTful接口文档 - 神奇Sam - 博客园_files/analytics.js.下载"></script><script src="./Spring Boot 系列（七）Swagger2-生成RESTful接口文档 - 神奇Sam - 博客园_files/jquery.js.下载" type="text/javascript"></script>  
<script type="text/javascript">var currentBlogApp = 'magicalSam', cb_enable_mathjax=false;var isLogined=false;</script>
<script src="./Spring Boot 系列（七）Swagger2-生成RESTful接口文档 - 神奇Sam - 博客园_files/blog-common.js.下载" type="text/javascript"></script>
<style type="text/css">
[id^="ad_"] {display:none!important;display:none}</style>
</head>
<body>
<a name="top"></a>

<!--done-->
<div id="home">
<div id="header">
	<div id="blogTitle">
	<a id="lnkBlogLogo" href="http://www.cnblogs.com/magicalSam/"><img id="blogLogo" src="./Spring Boot 系列（七）Swagger2-生成RESTful接口文档 - 神奇Sam - 博客园_files/logo.gif" alt="返回主页"></a>			
		
<!--done-->
<h1><a id="Header1_HeaderTitle" class="headermaintitle" href="http://www.cnblogs.com/magicalSam/">神奇Sam</a></h1>
<h2>神奇Sam的博客</h2>



		
	</div><!--end: blogTitle 博客的标题和副标题 -->
	<div id="navigator">
		
<ul id="navList">
<li><a id="blog_nav_sitehome" class="menu" href="http://www.cnblogs.com/">博客园</a></li>
<li><a id="blog_nav_myhome" class="menu" href="http://www.cnblogs.com/magicalSam/">首页</a></li>
<li><a id="blog_nav_newpost" class="menu" rel="nofollow" href="https://i.cnblogs.com/EditPosts.aspx?opt=1">新随笔</a></li>
<li><a id="blog_nav_contact" class="menu" rel="nofollow" href="https://msg.cnblogs.com/send/%E7%A5%9E%E5%A5%87Sam">联系</a></li>
<li><a id="blog_nav_rss" class="menu" href="http://www.cnblogs.com/magicalSam/rss">订阅</a>
<!--<a id="blog_nav_rss_image" class="aHeaderXML" href="http://www.cnblogs.com/magicalSam/rss"><img src="//www.cnblogs.com/images/xml.gif" alt="订阅" /></a>--></li>
<li><a id="blog_nav_admin" class="menu" rel="nofollow" href="https://i.cnblogs.com/">管理</a></li>
</ul>
		<div class="blogStats">
			
			<div id="blog_stats">
<span id="stats_post_count">随笔 - 17&nbsp; </span>
<span id="stats_article_count">文章 - 0&nbsp; </span>
<span id="stats-comment_count">评论 - 2</span>
</div>
			
		</div><!--end: blogStats -->
	</div><!--end: navigator 博客导航栏 -->
</div><!--end: header 头部 -->

<div id="main">
	<div id="mainContent">
	<div class="forFlow">
		
<div id="post_detail">
<!--done-->
<div id="topics">
	<div class="post">
		<h1 class="postTitle">
			<a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/magicalSam/p/7197533.html">Spring Boot 系列（七）Swagger2-生成RESTful接口文档</a>
		</h1>
		<div class="clear"></div>
		<div class="postBody">
			<div id="cnblogs_post_body" class="cnblogs-markdown"><h4 id="swagger-是一个规范和完整的框架用于生成描述调用和可视化-restful-风格的-web-服务总体目标是使客户端和文件系统作为服务器以同样的速度来更新文件的方法参数和模型紧密集成到服务器端的代码允许api来始终保持同步">Swagger 是一个规范和完整的框架，用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。总体目标是使客户端和文件系统作为服务器以同样的速度来更新。文件的方法，参数和模型紧密集成到服务器端的代码，允许API来始终保持同步。</h4>
<h2 id="开始">开始</h2>
<h3 id="pom.xml-添加依赖">1、pom.xml 添加依赖：</h3>
<pre><code class="hljs django"><span class="xml"><span class="hljs-comment">&lt;!-- swagger RESTful API 文档 --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>io.springfox<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>springfox-swagger2<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.2.2<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>io.springfox<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>springfox-swagger-ui<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.2.2<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span></span></code></pre>
<h3 id="创建-user-实体">2、创建 User 实体</h3>
<pre><code class="hljs groovy"><span class="hljs-keyword">package</span> com.sam.demo.domain;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@author</span> sam
 * <span class="hljs-doctag">@since</span> 2017/7/17
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span> {</span>

    <span class="hljs-keyword">private</span> Long id;
    <span class="hljs-keyword">private</span> String name;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> age;

    <span class="hljs-comment">//getter &amp; setter</span>
}
</code></pre>
<h3 id="在-application.java-同级创建-swagger2.java">3、在 Application.java 同级创建 Swagger2.java</h3>
<pre><code class="hljs swift">package com.sam.demo;

<span class="hljs-keyword">import</span> org.springframework.context.annotation.Bean;
<span class="hljs-keyword">import</span> org.springframework.context.annotation.Configuration;
<span class="hljs-keyword">import</span> springfox.documentation.builders.ApiInfoBuilder;
<span class="hljs-keyword">import</span> springfox.documentation.builders.PathSelectors;
<span class="hljs-keyword">import</span> springfox.documentation.builders.RequestHandlerSelectors;
<span class="hljs-keyword">import</span> springfox.documentation.service.ApiInfo;
<span class="hljs-keyword">import</span> springfox.documentation.spi.DocumentationType;
<span class="hljs-keyword">import</span> springfox.documentation.spring.web.plugins.Docket;
<span class="hljs-keyword">import</span> springfox.documentation.swagger2.annotations.EnableSwagger2;

<span class="hljs-comment">/**
 * @author sam
 * @since 2017/7/17
 */</span>
@<span class="hljs-type">Configuration</span>
@<span class="hljs-type">EnableSwagger2</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Swagger2</span> </span>{

    @<span class="hljs-type">Bean</span>
    <span class="hljs-keyword">public</span> <span class="hljs-type">Docket</span> createRestApi() {

        <span class="hljs-type">ApiInfo</span> apiInfo = new <span class="hljs-type">ApiInfoBuilder</span>()
                .title(<span class="hljs-string">"Sam 项目接口文档"</span>)
                .description(<span class="hljs-string">"Magical Sam 项目的接口文档，符合RESTful API。"</span>)
                .version(<span class="hljs-string">"1.0"</span>)
                .build();

        <span class="hljs-keyword">return</span> new <span class="hljs-type">Docket</span>(<span class="hljs-type">DocumentationType</span>.<span class="hljs-type">SWAGGER_2</span>)
                .apiInfo(apiInfo)
                .select()
                .apis(<span class="hljs-type">RequestHandlerSelectors</span>.basePackage(<span class="hljs-string">"com.sam.demo.controller"</span>)) <span class="hljs-comment">//以扫描包的方式</span>
                .paths(<span class="hljs-type">PathSelectors</span>.any())
                .build();
    }

}
</code></pre>
<h4 id="其中-.apisrequesthandlerselectors.basepackagecom.sam.demo.controller-指定了以扫描包的方式进行会把com.sam.demo.controller包下的controller都扫描到">其中 .apis(RequestHandlerSelectors.basePackage("com.sam.demo.controller")) 指定了以扫描包的方式进行，会把com.sam.demo.controller包下的controller都扫描到。</h4>
<h3 id="创建-usercontroller.java">4、创建 UserController.java</h3>
<pre><code class="hljs groovy"><span class="hljs-keyword">package</span> com.sam.demo.controller;

<span class="hljs-keyword">import</span> com.sam.demo.domain.User;
<span class="hljs-keyword">import</span> io.swagger.annotations.*;
<span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.*;

<span class="hljs-keyword">import</span> java.util.ArrayList;
<span class="hljs-keyword">import</span> java.util.List;

<span class="hljs-comment">/**
 * <span class="hljs-doctag">@author</span> sam
 * <span class="hljs-doctag">@since</span> 2017/7/14
 */</span>
<span class="hljs-meta">@Api</span>(value = <span class="hljs-string">"用户模块"</span>)
<span class="hljs-meta">@RestController</span>
<span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">"/user"</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserController</span> {</span>

    <span class="hljs-comment">/**
     * 获取单个用户
     *
     * <span class="hljs-doctag">@param</span> id
     * <span class="hljs-doctag">@return</span>
     */</span>
    <span class="hljs-meta">@ApiOperation</span>(value = <span class="hljs-string">"获取单个用户"</span>, notes = <span class="hljs-string">"传入id获取单个用户"</span>)
<span class="hljs-comment">//    @ApiImplicitParam(name = "id", value = "用户id", required = true, paramType = "path", dataType = "Long") //注意：paramType需要指定为path,不然不能正常获取</span>
    <span class="hljs-meta">@RequestMapping</span>(value = <span class="hljs-string">"/{id}"</span>, method = RequestMethod.GET)
    <span class="hljs-keyword">public</span> String user(<span class="hljs-meta">@ApiParam</span>(value = <span class="hljs-string">"用户Id"</span>, required = <span class="hljs-literal">true</span>) <span class="hljs-meta">@PathVariable</span> Long id) {
        <span class="hljs-keyword">return</span> <span class="hljs-string">"user id :"</span> + id;
    }

    <span class="hljs-comment">/**
     * 获取用户列表
     *
     * <span class="hljs-doctag">@return</span>
     */</span>
    <span class="hljs-meta">@ApiOperation</span>(value = <span class="hljs-string">"获取用户列表"</span>, notes = <span class="hljs-string">"获取用户列表"</span>)
    <span class="hljs-meta">@RequestMapping</span>(value = <span class="hljs-string">""</span>, method = RequestMethod.GET)
    <span class="hljs-keyword">public</span> List list() {
        List list = <span class="hljs-keyword">new</span> ArrayList();
        list.add(<span class="hljs-string">"Sam1"</span>);
        list.add(<span class="hljs-string">"Sam2"</span>);
        list.add(<span class="hljs-string">"Sam3"</span>);
        <span class="hljs-keyword">return</span> list;
    }

    <span class="hljs-comment">/**
     * 新建用户
     *
     * <span class="hljs-doctag">@param</span> user
     * <span class="hljs-doctag">@return</span>
     */</span>
    <span class="hljs-meta">@ApiOperation</span>(value = <span class="hljs-string">"新建用户"</span>, notes = <span class="hljs-string">"新建一个用户"</span>)
<span class="hljs-comment">//    @ApiImplicitParams({</span>
              <span class="hljs-comment">//注意：paramType需要指定为body</span>
<span class="hljs-comment">//            @ApiImplicitParam(name = "user", value = "用户数据", required = true, paramType = "body", dataType = "User") </span>
<span class="hljs-comment">//    })</span>
    <span class="hljs-meta">@RequestMapping</span>(value = <span class="hljs-string">""</span>, method = RequestMethod.POST)
    <span class="hljs-keyword">public</span> String create(<span class="hljs-meta">@ApiParam</span>(value = <span class="hljs-string">"用户数据"</span>, required = <span class="hljs-literal">true</span>) <span class="hljs-meta">@RequestBody</span> User user) {
        System.out.println(<span class="hljs-string">"user : "</span> + user.getName() + <span class="hljs-string">" "</span> + user.getAge());
        <span class="hljs-keyword">return</span> <span class="hljs-string">"success 新建user : "</span> + user.getName() + <span class="hljs-string">" "</span> + user.getAge();
    }


    <span class="hljs-comment">/**
     * 删除用户
     *
     * <span class="hljs-doctag">@return</span>
     */</span>
    <span class="hljs-meta">@ApiOperation</span>(value = <span class="hljs-string">"删除用户"</span>, notes = <span class="hljs-string">"通过用户id删除用户"</span>)
    <span class="hljs-meta">@ApiImplicitParam</span>(name = <span class="hljs-string">"id"</span>, value = <span class="hljs-string">"用户id"</span>, required = <span class="hljs-literal">true</span>, paramType = <span class="hljs-string">"path"</span>, dataType = <span class="hljs-string">"Long"</span>)
    <span class="hljs-meta">@RequestMapping</span>(value = <span class="hljs-string">"/{id}"</span>, method = RequestMethod.DELETE)
    <span class="hljs-keyword">public</span> String delete(<span class="hljs-meta">@PathVariable</span> Long id) {
        System.out.println(<span class="hljs-string">"删除用户："</span> + id);
        <span class="hljs-keyword">return</span> <span class="hljs-string">"success 删除user"</span> + id;
    }


    <span class="hljs-comment">/**
     * 更新用户
     *
     * <span class="hljs-doctag">@return</span>
     */</span>
    <span class="hljs-meta">@ApiOperation</span>(value = <span class="hljs-string">"更新用户"</span>, notes = <span class="hljs-string">"更新已存在用户"</span>)
    <span class="hljs-meta">@ApiImplicitParam</span>(name = <span class="hljs-string">"user"</span>, value = <span class="hljs-string">"用户数据"</span>, required = <span class="hljs-literal">true</span>, paramType = <span class="hljs-string">"body"</span>, dataType = <span class="hljs-string">"User"</span>)
    <span class="hljs-meta">@RequestMapping</span>(value = <span class="hljs-string">""</span>, method = RequestMethod.PUT)
    <span class="hljs-keyword">public</span> String update(<span class="hljs-meta">@RequestBody</span> User user) {
        System.out.println(<span class="hljs-string">"更新用户："</span> + user.getId() + <span class="hljs-string">" "</span> + user.getName() + <span class="hljs-string">" "</span> + user.getAge());
        <span class="hljs-keyword">return</span> <span class="hljs-string">"success 更新user : "</span> + user.getId() + <span class="hljs-string">" "</span> + user.getName() + <span class="hljs-string">" "</span> + user.getAge();
    }

}
</code></pre>
<h4 id="启动应用浏览器访问httplocalhost8080swagger-ui.html">启动应用，浏览器访问：<a href="http://localhost:8080/swagger-ui.html" class="uri">http://localhost:8080/swagger-ui.html</a></h4>
<h4 id="正常展示-api-接口文档界面如下">正常展示 api 接口文档界面，如下：</h4>
<p><img src="./Spring Boot 系列（七）Swagger2-生成RESTful接口文档 - 神奇Sam - 博客园_files/6083940-81a5c81de98bff9f.png" alt="Sam.png"></p>
<h4 id="注意1apiimplicitparam-和-apiparam-方式均能指定参数规则">注意1：@ApiImplicitParam 和 @ApiParam 方式均能指定参数规则。</h4>
<h4 id="注意2使用apiimplicitparam的时候需要指定paramtype">注意2：<a href="mailto:%E4%BD%BF%E7%94%A8@apiimplicitparam%E7%9A%84%E6%97%B6%E5%80%99">使用@ApiImplicitParam的时候</a>，需要指定paramType。</h4>
<blockquote>
<p>附：Swagger2相关注解介绍</p>
</blockquote>
<pre><code class="hljs perl">@Api：用在类上，说明该类的作用
@ApiOperation：用在方法上，说明方法的作用
@ApiImplicitParams：用在方法上包含一组参数说明
@ApiImplicitParam：用在 @ApiImplicitParams 注解中，指定一个请求参数的各个方面
    paramType：参数放在哪个地方
        · header --&gt; 请求参数的获取：@RequestHeader
        · query --&gt;请求参数的获取：@RequestParam
        · path（用于restful接口）--&gt; 请求参数的获取：@PathVariable
        · body（不常用）
        · form（不常用）
    name：参数名
    dataType：参数类型
    required：参数是否必须传
    value：参数的意思
    defaultValue：参数的默认值
@ApiResponses：用于表示一组响应
@ApiResponse：用在@ApiResponses中，一般用于表达一个错误的响应信息
    code：数字，例如<span class="hljs-number">400</span>
    message：信息，例如<span class="hljs-string">"请求参数没填好"</span>
    response：抛出异常的类
@ApiModel：描述一个Model的信息（这种一般用在post创建的时候，使用@RequestBody这样的场景，请求参数无法使用@ApiImplicitParam注解进行描述的时候）
@ApiModelProperty：描述一个model的属性</code></pre>
<blockquote>
<p>版权声明：本文为博主原创文章，转载请注明出处。</p>
</blockquote>
</div><div id="MySignature"></div>
<div class="clear"></div>
<div id="blog_post_info_block">
<div id="BlogPostCategory">分类: <a href="http://www.cnblogs.com/magicalSam/category/1035125.html" target="_blank">spring boot</a></div>
<div id="EntryTag">标签: <a href="http://www.cnblogs.com/magicalSam/tag/spring%20boot/">spring boot</a>, <a href="http://www.cnblogs.com/magicalSam/tag/Swagger2/">Swagger2</a>, <a href="http://www.cnblogs.com/magicalSam/tag/RESTful/">RESTful</a>, <a href="http://www.cnblogs.com/magicalSam/tag/%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3/">接口文档</a></div>
<div id="blog_post_info"><div id="green_channel">
        <a href="javascript:void(0);" id="green_channel_digg" onclick="DiggIt(7197533,cb_blogId,1);green_channel_success(this,&#39;谢谢推荐！&#39;);">好文要顶</a>
            <a id="green_channel_follow" onclick="follow(&#39;69efb20e-fbbd-4d77-1b12-08d49c352df3&#39;);" href="javascript:void(0);">关注我</a>
    <a id="green_channel_favorite" onclick="AddToWz(cb_entryId);return false;" href="javascript:void(0);">收藏该文</a>
    <a id="green_channel_weibo" href="javascript:void(0);" title="分享至新浪微博" onclick="ShareToTsina()"><img src="./Spring Boot 系列（七）Swagger2-生成RESTful接口文档 - 神奇Sam - 博客园_files/icon_weibo_24.png" alt=""></a>
    <a id="green_channel_wechat" href="javascript:void(0);" title="分享至微信" onclick="shareOnWechat()"><img src="./Spring Boot 系列（七）Swagger2-生成RESTful接口文档 - 神奇Sam - 博客园_files/wechat.png" alt=""></a>
</div>
<div id="author_profile">
    <div id="author_profile_info" class="author_profile_info">
            <a href="http://home.cnblogs.com/u/magicalSam/" target="_blank"><img src="./Spring Boot 系列（七）Swagger2-生成RESTful接口文档 - 神奇Sam - 博客园_files/20170712121159.png" class="author_avatar" alt=""></a>
        <div id="author_profile_detail" class="author_profile_info">
            <a href="http://home.cnblogs.com/u/magicalSam/">神奇Sam</a><br>
            <a href="http://home.cnblogs.com/u/magicalSam/followees">关注 - 0</a><br>
            <a href="http://home.cnblogs.com/u/magicalSam/followers">粉丝 - 3</a>
        </div>
    </div>
    <div class="clear"></div>
    <div id="author_profile_honor"></div>
    <div id="author_profile_follow">
                <a href="javascript:void(0);" onclick="follow(&#39;69efb20e-fbbd-4d77-1b12-08d49c352df3&#39;);return false;">+加关注</a>
    </div>
</div>
<div id="div_digg">
    <div class="diggit" onclick="votePost(7197533,&#39;Digg&#39;)">
        <span class="diggnum" id="digg_count">0</span>
    </div>
    <div class="buryit" onclick="votePost(7197533,&#39;Bury&#39;)">
        <span class="burynum" id="bury_count">0</span>
    </div>
    <div class="clear"></div>
    <div class="diggword" id="digg_tips">
    </div>
</div>
</div>
<div class="clear"></div>
<div id="post_next_prev"><a href="http://www.cnblogs.com/magicalSam/p/7196355.html" class="p_n_p_prefix">« </a> 上一篇：<a href="http://www.cnblogs.com/magicalSam/p/7196355.html" title="发布于2017-07-17 16:59">Spring Boot 系列（六）web开发-Spring Boot 热部署</a><br><a href="http://www.cnblogs.com/magicalSam/p/7198420.html" class="p_n_p_prefix">» </a> 下一篇：<a href="http://www.cnblogs.com/magicalSam/p/7198420.html" title="发布于2017-07-18 01:31">Spring Boot 系列（八）@ControllerAdvice 拦截异常并统一处理</a><br></div>
</div>


		</div>
		<div class="postDesc">posted @ <span id="post-date">2017-07-17 21:07</span> <a href="http://www.cnblogs.com/magicalSam/">神奇Sam</a> 阅读(<span id="post_view_count">914</span>) 评论(<span id="post_comment_count">0</span>)  <a href="https://i.cnblogs.com/EditPosts.aspx?postid=7197533" rel="nofollow">编辑</a> <a href="https://www.cnblogs.com/magicalSam/p/7197533.html#" onclick="AddToWz(7197533);return false;">收藏</a></div>
	</div>
	<script src="./Spring Boot 系列（七）Swagger2-生成RESTful接口文档 - 神奇Sam - 博客园_files/highlight.min.js.下载"></script><script>markdown_highlight();</script><script type="text/javascript">var allowComments=true,cb_blogId=366722,cb_entryId=7197533,cb_blogApp=currentBlogApp,cb_blogUserGuid='69efb20e-fbbd-4d77-1b12-08d49c352df3',cb_entryCreatedDate='2017/7/17 21:07:00';loadViewCount(cb_entryId);var cb_postType=1;</script>
	
</div><!--end: topics 文章、评论容器-->
</div><a name="!comments"></a><div id="blog-comments-placeholder"></div><script type="text/javascript">var commentManager = new blogCommentManager();commentManager.renderComments(0);</script>
<div id="comment_form" class="commentform">
<a name="commentform"></a>
<div id="divCommentShow"></div>
<div id="comment_nav"><span id="span_refresh_tips"></span><a href="javascript:void(0);" onclick="return RefreshCommentList();" id="lnk_RefreshComments" runat="server" clientidmode="Static">刷新评论</a><a href="https://www.cnblogs.com/magicalSam/p/7197533.html#" onclick="return RefreshPage();">刷新页面</a><a href="https://www.cnblogs.com/magicalSam/p/7197533.html#top">返回顶部</a></div>
<div id="comment_form_container"><div class="login_tips">注册用户登录后才能发表评论，请 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return login(&#39;commentform&#39;);">登录</a> 或 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return register();">注册</a>，<a href="http://www.cnblogs.com/">访问</a>网站首页。</div></div>
<div class="ad_text_commentbox" id="ad_text_under_commentbox"></div>
<div id="ad_t2"><a href="http://www.ucancode.com/index.htm" target="_blank">【推荐】50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库</a><br><a href="http://xc.hubwiz.com/course/592ee9b2b343f27b0ae1ba99?affid=cnblogs" target="_blank">【推荐】Vue.js 2.x 快速入门，大量高效实战示例</a><br><a href="https://cloud.tencent.com/act/campus?fromSource=gwzcw.613398.613398.613398" target="_blank">【活动】腾讯云 学生专属优惠套餐 多规格选择</a><br><a href="https://cloud.tencent.com/community/article/303682?fromSource=gwzcw.614532.614532.614532" target="_blank">【活动】释放技术的想象-解码腾讯云软件架构与应用</a><br></div>
<div id="opt_under_post"></div>
<div id="cnblogs_c1" class="c_ad_block"><a href="http://www.gcpowertools.com.cn/products/spreadservices/?utm_source=cnblogs&amp;utm_medium=blogpage&amp;utm_term=bottom&amp;utm_content=Spreadbiaoge&amp;utm_campaign=community" target="_blank"><img width="300" height="250" src="./Spring Boot 系列（七）Swagger2-生成RESTful接口文档 - 神奇Sam - 博客园_files/24442-20171114102308171-1147697076.png" alt="葡萄城1114"></a></div>
<div id="under_post_news"><div class="itnews c_ad_block"><b>最新IT新闻</b>:<br> ·  <a href="http://news.cnblogs.com/n/582657/" target="_blank">京东要用机器人和无人机对抗阿里巴巴 刘强东到底胜算几何？</a><br> ·  <a href="http://news.cnblogs.com/n/582656/" target="_blank">TF Lite只是故事的一部分，谷歌还一并介绍了新的模型压缩方法</a><br> ·  <a href="http://news.cnblogs.com/n/582655/" target="_blank">“大灰狼”远控开发者被曝猝死</a><br> ·  <a href="http://news.cnblogs.com/n/582654/" target="_blank">UC浏览器遭Google Play下架，被指存在隐私问题</a><br> ·  <a href="http://news.cnblogs.com/n/582653/" target="_blank">董明珠：不反对在国外买技术但真正创造者要自主研发</a><br>» <a href="http://news.cnblogs.com/" title="IT新闻" target="_blank">更多新闻...</a></div></div>
<div id="cnblogs_c2" class="c_ad_block"><a href="http://click.aliyun.com/m/34771/" target="_blank"><img width="468" height="60" src="./Spring Boot 系列（七）Swagger2-生成RESTful接口文档 - 神奇Sam - 博客园_files/24442-20171113120112796-634832761.jpg" alt="阿里云1113"></a></div>
<div id="under_post_kb"><div class="itnews c_ad_block" id="kb_block"><b>最新知识库文章</b>:<br><div id="kb_recent"> ·  <a href="http://kb.cnblogs.com/page/563790/" target="_blank">关于编程，你的练习是不是有效的？</a><br> ·  <a href="http://kb.cnblogs.com/page/581467/" target="_blank">改善程序员生活质量的 3+10 习惯</a><br> ·  <a href="http://kb.cnblogs.com/page/568841/" target="_blank">NASA的10条代码编写原则</a><br> ·  <a href="http://kb.cnblogs.com/page/578502/" target="_blank">为什么你参加了那么多培训，却依然表现平平？</a><br> ·  <a href="http://kb.cnblogs.com/page/579832/" target="_blank">写给初学前端工程师的一封信</a><br></div>» <a href="http://kb.cnblogs.com/" target="_blank">更多知识库文章...</a></div></div>
<div id="HistoryToday" class="c_ad_block"></div>
<script type="text/javascript">
    fixPostBody();
    setTimeout(function () { incrementViewCount(cb_entryId); }, 50);
    deliverAdT2();
    deliverAdC1();
    deliverAdC2();    
    loadNewsAndKb();
    loadBlogSignature();
    LoadPostInfoBlock(cb_blogId, cb_entryId, cb_blogApp, cb_blogUserGuid);
    GetPrevNextPost(cb_entryId, cb_blogId, cb_entryCreatedDate, cb_postType);
    loadOptUnderPost();
    GetHistoryToday(cb_blogId, cb_blogApp, cb_entryCreatedDate);   
</script>
</div>


	</div><!--end: forFlow -->
	</div><!--end: mainContent 主体内容容器-->

	<div id="sideBar">
		<div id="sideBarMain">
			
<!--done-->
<div class="newsItem">
<h3 class="catListTitle">公告</h3>
	<div id="blog-news"><div id="profile_block">昵称：<a href="http://home.cnblogs.com/u/magicalSam/">神奇Sam</a><br>园龄：<a href="http://home.cnblogs.com/u/magicalSam/" title="入园时间：2017-07-12">4个月</a><br>粉丝：<a href="http://home.cnblogs.com/u/magicalSam/followers/">3</a><br>关注：<a href="http://home.cnblogs.com/u/magicalSam/followees/">0</a><div id="p_b_follow"><a href="javascript:void(0);" onclick="follow(&#39;69efb20e-fbbd-4d77-1b12-08d49c352df3&#39;)">+加关注</a></div></div></div><script type="text/javascript">loadBlogNews();</script>
</div>

			<div id="blog-calendar" style=""><table id="blogCalendar" class="Cal" cellspacing="0" cellpadding="0" title="日历">
	<tbody><tr><td colspan="7"><table class="CalTitle" cellspacing="0">
		<tbody><tr><td class="CalNextPrev"><a href="javascript:void(0);" onclick="loadBlogCalendar(&#39;2017/10/01&#39;);return false;">&lt;</a></td><td align="center">2017年11月</td><td class="CalNextPrev" align="right"><a href="javascript:void(0);" onclick="loadBlogCalendar(&#39;2017/12/01&#39;);return false;">&gt;</a></td></tr>
	</tbody></table></td></tr><tr><th class="CalDayHeader" align="center" abbr="日" scope="col">日</th><th class="CalDayHeader" align="center" abbr="一" scope="col">一</th><th class="CalDayHeader" align="center" abbr="二" scope="col">二</th><th class="CalDayHeader" align="center" abbr="三" scope="col">三</th><th class="CalDayHeader" align="center" abbr="四" scope="col">四</th><th class="CalDayHeader" align="center" abbr="五" scope="col">五</th><th class="CalDayHeader" align="center" abbr="六" scope="col">六</th></tr><tr><td class="CalOtherMonthDay" align="center">29</td><td class="CalOtherMonthDay" align="center">30</td><td class="CalOtherMonthDay" align="center">31</td><td align="center">1</td><td align="center">2</td><td align="center">3</td><td class="CalWeekendDay" align="center">4</td></tr><tr><td class="CalWeekendDay" align="center">5</td><td align="center">6</td><td align="center">7</td><td align="center">8</td><td align="center">9</td><td align="center">10</td><td class="CalWeekendDay" align="center">11</td></tr><tr><td class="CalWeekendDay" align="center">12</td><td align="center">13</td><td align="center">14</td><td align="center">15</td><td class="CalTodayDay" align="center">16</td><td align="center">17</td><td class="CalWeekendDay" align="center">18</td></tr><tr><td class="CalWeekendDay" align="center">19</td><td align="center">20</td><td align="center">21</td><td align="center">22</td><td align="center">23</td><td align="center">24</td><td class="CalWeekendDay" align="center">25</td></tr><tr><td class="CalWeekendDay" align="center">26</td><td align="center">27</td><td align="center">28</td><td align="center">29</td><td align="center">30</td><td class="CalOtherMonthDay" align="center">1</td><td class="CalOtherMonthDay" align="center">2</td></tr><tr><td class="CalOtherMonthDay" align="center">3</td><td class="CalOtherMonthDay" align="center">4</td><td class="CalOtherMonthDay" align="center">5</td><td class="CalOtherMonthDay" align="center">6</td><td class="CalOtherMonthDay" align="center">7</td><td class="CalOtherMonthDay" align="center">8</td><td class="CalOtherMonthDay" align="center">9</td></tr>
</tbody></table></div><script type="text/javascript">loadBlogDefaultCalendar();</script>
			
			<div id="leftcontentcontainer">
				<div id="blog-sidecolumn"><div id="sidebar_search" class="sidebar-block">
<div id="sidebar_search" class="mySearch">
<h3 class="catListTitle">搜索</h3>
<div id="sidebar_search_box">
<div id="widget_my_zzk" class="div_my_zzk"><input type="text" id="q" onkeydown="return zzk_go_enter(event);" class="input_my_zzk">&nbsp;<input onclick="zzk_go()" type="button" value="找找看" id="btnZzk" class="btn_my_zzk"></div>
<div id="widget_my_google" class="div_my_zzk"><input type="text" name="google_q" id="google_q" onkeydown="return google_go_enter(event)" class="input_my_zzk">&nbsp;<input onclick="google_go()" type="button" value="谷歌搜索" class="btn_my_zzk"></div>
</div>
</div>

</div><div id="sidebar_shortcut" class="sidebar-block">
<div class="catListLink">
<h3 class="catListTitle">常用链接</h3>
<ul>
<li><a href="http://www.cnblogs.com/magicalSam/p/" title="我的博客的随笔列表">我的随笔</a></li><li><a href="http://www.cnblogs.com/magicalSam/MyComments.html" title="我发表过的评论列表">我的评论</a></li><li><a href="http://www.cnblogs.com/magicalSam/OtherPosts.html" title="我评论过的随笔列表">我的参与</a></li><li><a href="http://www.cnblogs.com/magicalSam/RecentComments.html" title="我的博客的评论列表">最新评论</a></li><li><a href="http://www.cnblogs.com/magicalSam/tag/" title="我的博客的标签列表">我的标签</a></li>
</ul>
<div id="itemListLin_con" style="display:none;">
<ul>

</ul>
</div>
</div></div><div id="sidebar_toptags" class="sidebar-block">
<div class="catListTag">
<h3 class="catListTitle">我的标签</h3>
<ul>
<li><a href="http://www.cnblogs.com/magicalSam/tag/spring%20boot/">spring boot</a>(10)</li><li><a href="http://www.cnblogs.com/magicalSam/tag/java/">java</a>(5)</li><li><a href="http://www.cnblogs.com/magicalSam/tag/java%E6%95%8F%E6%84%9F%E8%AF%8D%E8%BF%87%E6%BB%A4/">java敏感词过滤</a>(2)</li><li><a href="http://www.cnblogs.com/magicalSam/tag/java%E6%B3%A8%E8%A7%A3/">java注解</a>(2)</li><li><a href="http://www.cnblogs.com/magicalSam/tag/%E6%95%8F%E6%84%9F%E8%AF%8D%E8%BF%87%E6%BB%A4/">敏感词过滤</a>(2)</li><li><a href="http://www.cnblogs.com/magicalSam/tag/%E8%87%AA%E5%AE%9A%E4%B9%89%E6%B3%A8%E8%A7%A3/">自定义注解</a>(2)</li><li><a href="http://www.cnblogs.com/magicalSam/tag/ControllerAdvice/">ControllerAdvice</a>(1)</li><li><a href="http://www.cnblogs.com/magicalSam/tag/FreeMarker/">FreeMarker</a>(1)</li><li><a href="http://www.cnblogs.com/magicalSam/tag/https%E9%85%8D%E7%BD%AE/">https配置</a>(1)</li><li><a href="http://www.cnblogs.com/magicalSam/tag/%E6%A8%A1%E6%9D%BF%E5%BC%95%E6%93%8E/">模板引擎</a>(1)</li><li><a href="http://www.cnblogs.com/magicalSam/tag/">更多</a></li>
</ul>
</div></div><div id="sidebar_categories">
<div id="sidebar_postcategory" class="catListPostCategory sidebar-block">
<h3 class="catListTitle">随笔分类</h3>

<ul>

<li><a id="CatList_LinkList_0_Link_0" href="http://www.cnblogs.com/magicalSam/category/1034421.html">java(6)</a> </li>

<li><a id="CatList_LinkList_0_Link_1" href="http://www.cnblogs.com/magicalSam/category/1033580.html">Linux(2)</a> </li>

<li><a id="CatList_LinkList_0_Link_2" href="http://www.cnblogs.com/magicalSam/category/1035125.html">spring boot(10)</a> </li>

<li><a id="CatList_LinkList_0_Link_3" href="http://www.cnblogs.com/magicalSam/category/1033769.html">其他(1)</a> </li>

</ul>

</div>

<div id="sidebar_postarchive" class="catListPostArchive sidebar-block">
<h3 class="catListTitle">随笔档案</h3>

<ul>

<li><a id="CatList_LinkList_1_Link_0" href="http://www.cnblogs.com/magicalSam/archive/2017/09.html">2017年9月 (4)</a> </li>

<li><a id="CatList_LinkList_1_Link_1" href="http://www.cnblogs.com/magicalSam/archive/2017/07.html">2017年7月 (13)</a> </li>

</ul>

</div>

</div><div id="sidebar_recentcomments" class="sidebar-block"><div id="recent_comments_wrap">
<div class="catListComment">
<h3 class="catListTitle">最新评论</h3>

	<div id="RecentCommentsBlock"><ul>
        <li class="recent_comment_title"><a href="http://www.cnblogs.com/magicalSam/p/7198420.html#3840454">1. Re:Spring Boot 系列（八）@ControllerAdvice 拦截异常并统一处理</a></li>
        <li class="recent_comment_body">博主, @ControllerAdvice+@ExceptionHandler 处理异常适用spring mvc吗？</li>
        <li class="recent_comment_author">--yyuan01</li>
        <li class="recent_comment_title"><a href="http://www.cnblogs.com/magicalSam/p/7189421.html#3829486">2. Re:Spring Boot 系列（三）属性配置&amp;自定义属性配置</a></li>
        <li class="recent_comment_body">com.basecode.id=2com.basecode.name=\u5BA2\u5546com.basecode.name2=${name}我这么写为什么会报错啊 Could not res......</li>
        <li class="recent_comment_author">--xiaoyuemushan</li>
</ul>
</div>
</div>
</div></div><div id="sidebar_topviewedposts" class="sidebar-block"><div id="topview_posts_wrap">
<div class="catListView">
<h3 class="catListTitle">阅读排行榜</h3>
	<div id="TopViewPostsBlock"><ul><li><a href="http://www.cnblogs.com/magicalSam/p/7198420.html">1. Spring Boot 系列（八）@ControllerAdvice 拦截异常并统一处理(8266)</a></li><li><a href="http://www.cnblogs.com/magicalSam/p/7189476.html">2. Spring Boot 系列（四）静态资源处理(5500)</a></li><li><a href="http://www.cnblogs.com/magicalSam/p/7189421.html">3. Spring Boot 系列（三）属性配置&amp;自定义属性配置(4428)</a></li><li><a href="http://www.cnblogs.com/magicalSam/p/magicalSam.html">4. 在Linux安装配置Tomcat 并部署web应用 ( 三种方式 )(4114)</a></li><li><a href="http://www.cnblogs.com/magicalSam/p/7196355.html">5. Spring Boot 系列（六）web开发-Spring Boot 热部署(3746)</a></li></ul></div>
</div>
</div></div><div id="sidebar_topcommentedposts" class="sidebar-block"><div id="topfeedback_posts_wrap">
<div class="catListFeedback">
<h3 class="catListTitle">评论排行榜</h3>
	<div id="TopFeedbackPostsBlock"><ul><li><a href="http://www.cnblogs.com/magicalSam/p/7189421.html">1. Spring Boot 系列（三）属性配置&amp;自定义属性配置(1)</a></li><li><a href="http://www.cnblogs.com/magicalSam/p/7198420.html">2. Spring Boot 系列（八）@ControllerAdvice 拦截异常并统一处理(1)</a></li></ul></div>
</div>
</div></div><div id="sidebar_topdiggedposts" class="sidebar-block"><div id="topdigg_posts_wrap">
<div class="catListView">
<h3 class="catListTitle">推荐排行榜</h3>
<div id="TopDiggPostsBlock"><ul><li><a href="http://www.cnblogs.com/magicalSam/p/7189421.html">1. Spring Boot 系列（三）属性配置&amp;自定义属性配置(2)</a></li><li><a href="http://www.cnblogs.com/magicalSam/p/7198420.html">2. Spring Boot 系列（八）@ControllerAdvice 拦截异常并统一处理(1)</a></li></ul></div>
</div></div></div></div><script type="text/javascript">loadBlogSideColumn();</script>
			</div>
			
		</div><!--end: sideBarMain -->
	</div><!--end: sideBar 侧边栏容器 -->
	<div class="clear"></div>
	</div><!--end: main -->
	<div class="clear"></div>
	<div id="footer">
		
<!--done-->
Copyright ©2017 神奇Sam
	</div><!--end: footer -->
</div><!--end: home 自定义的最大容器 -->


</body></html>